<?php declare(strict_types=1);
/**
 * This file is part of Swoft.
 *
 * @link     https://swoft.org
 * @document https://swoft.org/docs
 * @contact  group@swoft.org
 * @license  https://github.com/swoft-cloud/swoft/blob/master/LICENSE
 */

namespace App\Http\Controller\Test;

use InvalidArgumentException;
use Swoft\Cache\Cache;
use Swoft\Http\Server\Annotation\Mapping\Controller;
use Swoft\Http\Server\Annotation\Mapping\RequestMapping;
use Swoft\Http\Server\Annotation\Mapping\RequestMethod;

/**
 * Class SwoftCacheController
 *
 * @since 2.0.8
 *
 * @Controller(prefix="cache")
 */
class SwoftCacheController
{
    /**
     * @RequestMapping(route="set",method={RequestMethod::GET})
     *
     * @return array
     * @throws InvalidArgumentException
     */
    public function set()
    {
        $ok  = Cache::set('ckey', 'cache value');
        $ok1 = Cache::set('ckey1', 'cache value2', 5);

        return ['ckey' => $ok, 'ckey1' => $ok1];
    }

    /**
     * @RequestMapping(route="get",method={RequestMethod::GET})
     *
     * @return array
     * @throws InvalidArgumentException
     */
    public function get()
    {
        $val = Cache::get('ckey');

        return [
            'ckey'  => $val,
            'ckey1' => Cache::get('ckey1')
        ];
    }

    /**
     * @RequestMapping(route="del",method={RequestMethod::GET})
     *
     * @return array
     * @throws InvalidArgumentException
     */
    public function del()
    {
        return ['del' => Cache::delete('ckey')];
    }
}
